package com.xx.sg.controller;


import com.xx.sg.dbw.service.AlarmCountService;
import com.xx.sg.util.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/alarm/count")
@Tag(name = "报警统计", description = "报警统计")
public class AlarmCountController {

    @Autowired
    private AlarmCountService alarmCountService;

    @GetMapping("/classify")
    @Operation(summary = "类型数量统计", description = "类型数量统计")
    public R alarmClassifyCount() {
        Map<String, String> map = alarmCountService.alarmHistoryClassifyCount();

        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put("xData", new String[]{"手动接警", "红外监控", "卫星监测"});
        resultMap.put("yData", new String[]{
                String.valueOf(map.get("sd")),
                String.valueOf(map.get("hw")),
                String.valueOf(map.get("wx"))});
        return R.success(resultMap);
    }

    @GetMapping("/status")
    @Operation(summary = "状态数量统计", description = "状态数量统计")
    public R alarmHistoryStatusCount() {
        Map<String, String> map = alarmCountService.alarmHistoryStatusCount();

        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put("xData", new String[]{"误报", "已核实", "待处置", "已处置"});
        resultMap.put("yData", new String[]{
                String.valueOf(map.get("wb")),
                String.valueOf(map.get("yhs")),
                String.valueOf(map.get("dcz")),
                String.valueOf(map.get("ycz"))});
        return R.success(resultMap);
    }


    @GetMapping("/classifyDay")
    @Operation(summary = "状态数量统计", description = "状态数量统计")
    public R alarmHistoryClassifyDayCount() {
        List<Map<String, Object>> list = alarmCountService.alarmHistoryClassifyDayCount();

        Map<String, Object> resultMap = new HashMap<>();

        List<String> dateList = new ArrayList<>();
        List<String> hwList = new ArrayList<>();
        List<String> sdList = new ArrayList<>();
        List<String> wxList = new ArrayList<>();
        for (Map<String, Object> map : list) {
            dateList.add(map.get("alarm_date").toString());
            hwList.add(map.get("hw_count").toString());
            sdList.add(map.get("sd_count").toString());
            wxList.add(map.get("wx_count").toString());
        }

        resultMap.put("xData", dateList);
        resultMap.put("hwData", hwList);
        resultMap.put("sdData", sdList);
        resultMap.put("wxData", wxList);
        return R.success(resultMap);
    }
}
